/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sinocloud.springmvc.demo.dao.impl;

import com.sinocloud.springmvc.demo.dao.UserDao;
import com.sinocloud.springmvc.demo.model.User;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Service;

/**
 *
 * @author zhaoyuan
 */
@Service
public class UserDaoImpl implements UserDao {
     
    JdbcTemplate jdbcTemplate;
    private final Logger log=Logger.getLogger(this.getClass());

    @Override
    public User queryById(String id) {
        System.out.println("jdbcTemplate:"+jdbcTemplate);
        log.info("log测试");
        String sql = "select * from user where id=?";
        final User u = new User();
        final Object[] params = new Object[]{id};
        jdbcTemplate.query(sql, params, new RowCallbackHandler() {
            @Override
            public void processRow(ResultSet rs) throws SQLException {
                u.setId(rs.getString("ID"));
                u.setName(rs.getString("NAME"));
                u.setPassword(rs.getString("PASSWORD"));
            }
        });

        return u;
    }

    @Override
    public List<User> queryByName(String name) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean update(User user) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean insert(User user) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

}
